package model

import (
	"cloud-disk/xorm"
	"time"
)

type ShareBasic struct {
	Id                     uint64 ``
	Identity               string
	UserIdentity           string
	UserRepositoryIdentity string
	RepositoryIdentity     string
	ExpiredTime            int
	ClickNum               int
	CreatedAt              time.Time `xorm:"created"`
	UpdatedAt              time.Time `xorm:"updated"`
	DeletedAt              time.Time `xorm:"deleted"`
}

//TableName 指定表名
func (table ShareBasic) TableName() string {
	return "share_basic"
}

//CreateShareBasic 创建分享
func (table *ShareBasic) CreateShareBasic(sb *ShareBasic) (*ShareBasic, error) {
	_, err := xorm.Xorm.Insert(sb)
	if err != nil {
		return nil, err
	}
	return sb, err
}

//GetShareBasic 获取分享
func (table *ShareBasic) GetShareBasic(identity string) (sb *ShareBasic, has bool, err error) {
	sb = new(ShareBasic)
	has, err = xorm.Xorm.Where("identity = ?", identity).Get(sb)
	if err != nil {
		return nil, false, err
	}
	return sb, has, nil
}
